<template>
  <div class="sidebar">
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
      text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-sub-menu :index="item.index" :key="item.index">
            <template #title>
              <el-icon :size="size">
                <component :is="item.icon" />
              </el-icon>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs" :key="subItem.index">
              <el-menu-item :index="subItem.index">{{ subItem.title }}</el-menu-item>
            </template>
          </el-sub-menu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <el-icon :size="size">
              <component :is="item.icon" />
            </el-icon>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>
<script>
import { computed, watch } from "vue";
import { useStore } from "vuex";
import { useRoute } from "vue-router";
import { Edit, HomeFilled, Grid } from "@element-plus/icons";
export default {
  components: {
    Edit,
    HomeFilled,
    Grid,
  },
  setup() {
    const size = 12;
    const items = [
      {
        icon: "homeFilled",
        index: "/dashboard",
        title: "系统首页",
      },
      {
        icon: "edit",
        index: "/userAdmin",
        title: "用户管理",
        subs: [
          {
            index: "/userInfo",
            title: "用户信息",
          },
          {
            icon: "grid",
            index: "/userAdd",
            title: "用户添加",
          },
        ],
      },
      {
        icon: "edit",
        index: "articleAdmin",
        title: "文章管理",
        subs: [
          {
            index: "/articleInfo",
            title: "文章信息",
          },
          {
            icon: "grid",
            index: "/articleAdd",
            title: "文章添加",
          },
        ],
      },
      {
        icon: "edit",
        index: "ticketAdmin",
        title: "门票管理",
        subs: [
          {
            index: "/ticketInfo",
            title: "门票信息",
          },
          {
            index: "/ticketAdd",
            title: "门票添加",
          },

        ],
      },
      {
        icon: "edit",
        index: "orderAdmin",
        title: "订单管理",
        subs: [
          {
            index: "/orderInfo",
            title: "订单信息",
          },
          {
            index: "/orderAdd",
            title: "订单添加",
          },

        ],
      },
      {
        icon: "edit",
        index: "/attractionAdmin",
        title: "景点管理",
        subs: [
          {
            index: "/attractionInfo",
            title: "景点信息",
          },
          {
            index: "/attractionAdd",
            title: "景点添加",
          },

        ],
      },
      {
        icon: "edit",
        index: "/commentAdmin",
        title: "评论管理",
        subs: [
          {
            index: "/commentInfo",
            title: "评论信息",
          },
          {
            index: "/commentAdd",
            title: "评论添加",
          },

        ],
      }
      
    ];
    const route = useRoute();
    const onRoutes = computed(() => {
      return route.path;
    });
    const store = useStore();
    const collapse = computed(() => {
      return store.state.collapse;
    });
    return {
      size,
      items,
      onRoutes,
      collapse,
    };
  },
};
</script>
<style lang="scss" scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 200px;
}

.sidebar>ul {
  height: 100%;
}
</style>
